﻿var va="";
function zhifu(){
	    if($("input[name=radioName]:checked").size()!=0){
          va= $("input[name=radioName]:checked").val();    
                     callpay();
	    }else{
	    	alert("充值面额未选择");
	    }
}

//微信支付
function zhifuweixin(){
	   if(uuuuid!=""){
				$.ajax({
					url: urlcore+"/api/pay/wxpay2?userId="+uuuuid+"&money="+va,
					type: "get",
					dataType: 'json',
					contentType: "application/json;charset=utf-8",
					success:function(data){		
					var d = data.data;
					 WeixinJSBridge.invoke(
					    'getBrandWCPayRequest',
					    {
				           "appId":d.appId,    
				           "timeStamp":d.timeStamp,        
				           "nonceStr":d.nonceStr, 
				           "package":d.package,     
				           "signType":"MD5",        
				           "paySign":d.paySign 
				       },
					    function (res){
					    	alert(JSON.stringify(res));
					    	alert(res);
					         if(res.err_msg == "get_brand_wcpay_request:ok" ) {
					         	yuezhifu();
					         }else{
					         	alert("支付失败");
					         }
					    });
				},
					error:function() {
						/* Act on the event */
						alert("error");
					}
				});	
				
				}
	
}






 function callpay(){
		if (typeof WeixinJSBridge == "undefined"){
			    if (document.addEventListener){
		document.addEventListener('WeixinJSBridgeReady', zhifuweixin,false);
			    }else if (document.attachEvent){
        document.attachEvent('WeixinJSBridgeReady', zhifuweixin);
		document.attachEvent('onWeixinJSBridgeReady', zhifuweixin);
			    }
			    }else{
			        zhifuweixin();
			    }
			}
 


//余额支付
function yuezhifu(){
    	 $.ajax({
		url: urlcore + "/api/userAccount/Recharge",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"userId":uuuuid,
			"balanceMoney":va
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
              alert("充值成功!");		
           }
		},
		error: function() {
			alert("error");
		}
	});


}
/*

 function shengchengdingdan(va){
   		$.ajax({
		url: urlcore + "/api/order/addSomeOrder?money="+va,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) { 
				
			}else{
				window.location.href="index.html";
			}
		},
		error:function() {
			/* Act on the event
			alert("error");
		}
	});	
   }
*/